define(function(require,exports,module){

	require('common');
	//投资项目
	var tpl = require('../../tpl/myInvest.tpl');//载入tpl模板
	var url = '/member/invest/myInvestList.html?';
    var curId = $("#investProjectDiv");
    var pagerid = "kkpagerInvestProject";
  //初始化显示表格、搜索
    require.async(['./showTable','./search'],function(showTable,search){
        showTable.ajaxUrl(url,tpl,curId,pagerid);
        search.search(url,tpl,curId,pagerid);

        // 点击后重新加载列表分页搜索
        $(".invest_project").click(function(){
        	showTable.ajaxUrl(url,tpl,curId,pagerid);
        });
    });



	//查看回款
	$(".showWin").live("click",function(){
		var tenderId=$(this).attr("data-val");
		window.layer.open({
		    type: 1,
		    closeBtn: 1,
            title: "本项目待收记录",
		    area: ['874px', '350px'],
		    border: [1, 1, '#cecfd0'],
		    content: '<div class="tipsWrap w794" id="uncollectedRecordsDiv"><table class="table_content"><thead><tr><td>投资时间</td><td>投资金额</td><td>还款方式</td><td>计息起始日</td><td>待收日</td><td>待收本息</td><td>状态</td><td>期数</td></tr></thead><tbody id="member_table"></tbody></table><div id="kkpagerUncollectedRecords" class="kkpager"></div></div>',
		    success: function(layero){
		    	tpl = require('../../tpl/member/invest_showWin.tpl');
		    	url = '/member/invest/repayPlan.html?id=' + tenderId + '&size=5';
		    	curId = $("#uncollectedRecordsDiv");
		    	pagerid = "kkpagerUncollectedRecords";
		    	require.async(['./showTable','./search'],function(showTable,search){
		    		showTable.ajaxUrl(url,tpl,curId,pagerid);
			        search.search(url,tpl,curId,pagerid);
		    	});
		    },
		    cancel: function(index){
		    	layer.closeAll();

		    	tpl = require('../../tpl/myInvest.tpl');//载入tpl模板
		    	url = '/member/invest/myInvestList.html?';
		        curId = $("#investProjectDiv");
		        pagerid = "kkpagerInvestProject";
		        require.async(['./showTable','./search'],function(showTable,search){
			    	showTable.ajaxUrl(url,tpl,curId,pagerid);
			        search.search(url,tpl,curId,pagerid);
		        });
		    }
		});
	});

	// 我的投资tab选项卡
	$(".myInvestList").tabChange({
		isClick:true,
		isHover:false,
		childLi:".title_list li",//tab选项卡
		childContent:".list_div",//tab内容
		hoverClassName:"hover",//选中当前选项卡的样式
		callBack:false
	});

	function getQueryString(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = window.location.search.substr(1).match(reg);
		if (r != null) return unescape(r[2]); return null;
	}

	var tab=getQueryString("tab")
	if(tab=="3") {
		$("#oncallPlanDiv").show();
		$(".title_list").children().removeClass("hover");
		$(".title_list").children().eq(2).addClass("hover");
		$("#investProjectDiv").hide();
		var tpl = require('../../tpl/member/invest_repayPlan.tpl');//载入tpl模板
		var url = '/member/invest/allRepayPlan.html?';
		var curId = $("#oncallPlanDiv");
		var pagerid = "kkpagerOncallPlan";
		//初始化显示表格、搜索
		require.async(['./showTable','./search'],function(showTable,search){
			search.search(url,tpl,curId,pagerid);
			// 点击后重新加载列表分页搜索
			showTable.ajaxUrl(url,tpl,curId,pagerid);
		});
	}
})
